<?php /* Smarty version 2.6.18, created on 2015-10-17 16:32:05
         compiled from serverListEdit.html */ ?>
<?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "header.html", 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>
<?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "top.html", 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>
<?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "left.html", 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>
				<div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<script type="text/javascript">
							try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
						</script>

						<ul class="breadcrumb">
							<li>
								<i class="icon-home home-icon"></i>
								<a href="javascript:void(0);"></a>
							</li>
							<li class="active"><a href="index.php">首页</a></li>
						</ul><!-- .breadcrumb -->
					</div>

					<div class="page-content">

<div class="col-xs-12">
<div id="moveDevice" style="display:none" class="col-xs-12">
<div class="alert alert-info">
<form class="form-horizontal" role="form">
<div class="col-sm-12">
<div class="row">
<label class="col-sm-5 control-label no-padding-right" for="form-field-5">游戏</label>
<div class="col-sm-3"><select id="selectGame2">
	<option value="" >游戏</option>
	<?php if ($this->_tpl_vars['selectGames']): ?> <?php $_from = $this->_tpl_vars['selectGames']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['key'] => $this->_tpl_vars['value']):
?>
	<?php if ($this->_tpl_vars['nowGame'] == $this->_tpl_vars['value']): ?>
	<option value="<?php echo $this->_tpl_vars['value']; ?>
" selected><?php echo $this->_tpl_vars['value']; ?>
</option>
	<?php else: ?>
	<option value="<?php echo $this->_tpl_vars['value']; ?>
"><?php echo $this->_tpl_vars['value']; ?>
</option>
	<?php endif; ?> <?php endforeach; endif; unset($_from); ?> <?php endif; ?>
</select>
</div>
</div>

<div class="col-sm-12">
<div  class="row">
<label class="col-sm-5 control-label no-padding-right" for="form-field-5"></label>
</div>
</div>

<div class="col-sm-12">
<div class="row">
<label class="col-sm-5 control-label no-padding-right" for="form-field-5">平台</label>
<div class="col-sm-3">
<select id="platform2">
	<option value="" id="selectPlatform">平台</option>
	<?php if ($this->_tpl_vars['platforms']): ?> <?php $_from = $this->_tpl_vars['platforms']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['key'] => $this->_tpl_vars['value']):
?>
	<?php if ($this->_tpl_vars['platform'] == $this->_tpl_vars['value']): ?>
	<option value="<?php echo $this->_tpl_vars['value']; ?>
" selected><?php echo $this->_tpl_vars['value']; ?>
</option>
	<?php else: ?>
	<option value="<?php echo $this->_tpl_vars['value']; ?>
"><?php echo $this->_tpl_vars['value']; ?>
</option>
	<?php endif; ?> <?php endforeach; endif; unset($_from); ?> <?php endif; ?>
	
</select>
</div>
</div>
</div>


<div class="col-sm-12">
<div  class="row">
<label class="col-sm-5 control-label no-padding-right" for="form-field-5"></label>
</div>
</div>


<div class="col-sm-12">
<div  class="row">
<label class="col-sm-5 control-label no-padding-right" for="form-field-5"></label>
</div>
</div>


<div class="col-sm-12">
<div  class="row">
<label class="col-sm-5 control-label no-padding-right" for="form-field-5"></label>
</div>
</div>

<div class="col-sm-12">
<div class="row"><label
	class="col-sm-5 control-label no-padding-right" for="form-field-5">&nbsp;&nbsp;&nbsp;&nbsp;</label>
<div class="col-sm-2">
<center>
<button type="button" onClick="configure('select', 'move');"
	class="width-50 btn btn-sm btn-primary">配置</button>
</center>
</div>
</div>
</div>




</div>
</form>
</div>
</div>
</div>

<div id="pcDevice" style="display:block" class="col-xs-12">
<div class="alert alert-info">
<form class="form-horizontal" role="form">
<div class="row">

<div class="col-sm-2">
<div class="row">
<label class="col-sm-2 control-label no-padding-right" for="form-field-5">游戏</label>
<div class="col-sm-3"><select id="selectGame">
	<option value="" >游戏</option>
	<?php if ($this->_tpl_vars['selectGames']): ?> <?php $_from = $this->_tpl_vars['selectGames']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['key'] => $this->_tpl_vars['value']):
?>
	<?php if ($this->_tpl_vars['nowGame'] == $this->_tpl_vars['value']): ?>
	<option value="<?php echo $this->_tpl_vars['value']; ?>
" selected><?php echo $this->_tpl_vars['value']; ?>
</option>
	<?php else: ?>
	<option value="<?php echo $this->_tpl_vars['value']; ?>
"><?php echo $this->_tpl_vars['value']; ?>
</option>
	<?php endif; ?> <?php endforeach; endif; unset($_from); ?> <?php endif; ?>
</select>
</div>
</div>
</div>


<div class="col-sm-2">
<div class="row">
<label class="col-sm-2 control-label no-padding-right" for="form-field-5">平台</label>
<div class="col-sm-3">
<select id="platform">
	<option value="" id="selectPlatform">平台</option>
	
	<?php if ($this->_tpl_vars['platforms']): ?> <?php $_from = $this->_tpl_vars['platforms']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['key'] => $this->_tpl_vars['value']):
?>
	<?php if ($this->_tpl_vars['platform'] == $this->_tpl_vars['value']): ?>
	<option value="<?php echo $this->_tpl_vars['value']; ?>
" selected><?php echo $this->_tpl_vars['value']; ?>
</option>
	<?php else: ?>
	<option value="<?php echo $this->_tpl_vars['value']; ?>
"><?php echo $this->_tpl_vars['value']; ?>
</option>
	<?php endif; ?> <?php endforeach; endif; unset($_from); ?> <?php endif; ?>
	
</select>
</div>

</div>
</div>



<div class="col-sm-2">
<div class="row"><label
	class="col-sm-2 control-label no-padding-right" for="form-field-5">&nbsp;&nbsp;&nbsp;&nbsp;</label>
<div class="col-sm-9">
<center>
<button type="button" onClick="configure('select', 'pc');"
	class="width-50 btn btn-sm btn-primary">配置
</button>
</center>
</div>
</div>
</div>

</div>
</form>
</div>
</div>	

							
					<div class="col-xs-12" >			
								<div class="table-header">
									<!--   <a style="display:none" id="addGame" href="index.php?mod=Game&do=addGame"  class="pull-left"> 
											<font class="white"><i class="icon-user-md"></i>&nbsp;添加服
							    			 </font>
									 </a>
								  	<button class="btn btn-primary"  onclick="document.getElementById('addGame').click();return false;" >
										<font class="white"><i class="icon-user-md"></i>&nbsp;添加服  
										 </font>
									</button> -->
									服务器列表
								</div>

								<div class="table-responsive">
									<table id="sample-table-1" class="table table-striped table-bordered table-hover">
										<thead>	
											 <tr>
												<td class="col-xs-1"><input  disabled="disabled" type="text"  value="defaultSeverID" /></td>
												<td class="col-xs-1"><input type="text" id="defaultSeverID" value="<?php echo $this->_tpl_vars['defaultSeverID']; ?>
" /></td>
												<td class="col-xs-1"></td>
												<td class="col-xs-1"></td>
												<td class="col-xs-1"></td>
												<td class="col-xs-1"></td>
												<td class="col-xs-1">
												<div >
													&nbsp;&nbsp;
													<button valign="bottom" type="button" onclick="saveDefaultServerId();" class="btn btn-primary btn-sm">
														 保存
												    </button>
												</div>
												</td>
											</tr>
									   </thead>
									  
										<thead>
											<tr>
												<th>id</th>
												<th>name</th>
												<th>address</th>
												<th>port</th>
												<th>state</th>
												<th>order</th>		
												<th>操作</th>		
											</tr>
										</thead>

										<tbody id ="server_table">
											<?php if ($this->_tpl_vars['severs']): ?>
											<?php $_from = $this->_tpl_vars['severs']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['severs']):
?>
											<tr id ="<?php echo $this->_tpl_vars['severs']['id']; ?>
_tr" >
												<td class="col-xs-1"><input  disabled="disabled" type="text" id="<?php echo $this->_tpl_vars['severs']['id']; ?>
_id" value="<?php echo $this->_tpl_vars['severs']['id']; ?>
" /></td>
												<td class="col-xs-1"><input type="text" id="<?php echo $this->_tpl_vars['severs']['id']; ?>
_name" value="<?php echo $this->_tpl_vars['severs']['name']; ?>
" /></td>
												<td class="col-xs-1" ><input type="text" id="<?php echo $this->_tpl_vars['severs']['id']; ?>
_address" value="<?php echo $this->_tpl_vars['severs']['address']; ?>
"  /></td>
												<td class="col-xs-1"><input  type="text" id="<?php echo $this->_tpl_vars['severs']['id']; ?>
_port" value="<?php echo $this->_tpl_vars['severs']['port']; ?>
" /></td>
												<td class="col-xs-1"><input  type="text" id="<?php echo $this->_tpl_vars['severs']['id']; ?>
_state" value="<?php echo $this->_tpl_vars['severs']['state']; ?>
" /></td>
												<td class="col-xs-1"><input  type="text" id="<?php echo $this->_tpl_vars['severs']['id']; ?>
_order" value="<?php echo $this->_tpl_vars['severs']['order']; ?>
" /></td>	
												<td class="col-xs-1">
												<div >
													&nbsp;&nbsp;
													<button valign="bottom" type="button" onclick="formSubmit('<?php echo $this->_tpl_vars['severs']['id']; ?>
');" class="btn btn-primary btn-sm">
														 保存
												    </button>
												</div>
												</td>
											</tr>
											<?php endforeach; endif; unset($_from); ?>
											<?php endif; ?>
										</tbody>
									</table>
								</div><!-- /.table-responsive -->
								
								<div class="col-xs-12 col-sm-12" >
										<center>
										<input  type="text" id="new_server_id" placeholder="id"  />	
										<button class="btn btn-primary btn-sm"     onclick="addServer(document.getElementById('new_server_id').value)" >
											add  
										</button>
										</center>										
								</div>
								
							</div>	

					</div><!-- /.page-content -->
				</div><!-- /.main-content -->

		<script type="text/javascript">
			
		    // 添加一行server
			function addServer(id) {
				if(!id) {
					alert("id不能为空");
					return ;
				}
				
				var param = {};
				var s_id 			= "<?php echo $this->_tpl_vars['s_id']; ?>
";
				param['mod'] 		= 'ServerList';
				param['do'] 		= 'checkServerId';
				param['s_id'] 		= s_id;
				// 游戏的id
				param['id'] 	= id;
				
				// id加一个验证 已经存在的服 不予追加
				$.ajax({
					type:'POST',
					url:'index.php',
					data:param,
					dataType:'html',
					success:function(data) {
				 		var dataObj = eval("(" + data + ")");//转换为json对象
				 		
						if (dataObj.code != 1) {
							alert(dataObj.msg);
						} else {
							var type = "'save'";
							var name = dataObj.name;
							$("#server_table").append('<tr id ="'+id+'_tr" ><td class="col-xs-1"><input  disabled="disabled"  type="text" id="'+id+'_id" value="'+id+'" /></td> <td class="col-xs-1"><input type="text" id="'+id+'_name" value="'+name+id+'服" /></td> <td class="col-xs-1" ><input type="text" id="'+id+'_address" value=""  /></td> <td class="col-xs-1"><input  type="text" id="'+id+'_port" value="" /></td> <td class="col-xs-1"><input  type="text" id="'+id+'_state" value="full" /></td> <td class="col-xs-1"><input  type="text" id="'+id+'_order" value="'+id+'" /></td>  <td> <div > &nbsp;&nbsp; <button valign="bottom" type="button" onclick="formSubmit('+id+');" class="btn btn-primary btn-sm"> 保存 </button></div> </td> </tr>');
						} 
					}
				});
				
			/* 	var type = "'save'";
				var name = "霸业";
				$("#server_table").append('<tr id ="'+id+'_tr" ><td class="col-xs-1"><input  disabled="disabled"  type="text" id="'+id+'_id" value="'+id+'" /></td> <td class="col-xs-1"><input type="text" id="'+id+'_name" value="'+name+id+'服" /></td> <td class="col-xs-1" ><input type="text" id="'+id+'_address" value=""  /></td> <td class="col-xs-1"><input  type="text" id="'+id+'_port" value="" /></td> <td class="col-xs-1"><input  type="text" id="'+id+'_state" value="full" /></td> <td class="col-xs-1"><input  type="text" id="'+id+'_order" value="'+id+'" /></td>  <td> <div > &nbsp;&nbsp; <button valign="bottom" type="button" onclick="formSubmit('+id+');" class="btn btn-primary btn-sm"> 保存 </button></div> </td> </tr>');
	 		*/		
	 	}	
				
			
		function saveDefaultServerId() {
				
				var param = {};
				var s_id = "<?php echo $this->_tpl_vars['s_id']; ?>
";
				if(!s_id) {
					alert("s_id不存在,请联系管理员!");
					return ;
				}
				
				// 暂时不考虑适配
				var game 	 = $('#selectGame').val();
				var platform = $('#platform').val();
				var defaultSeverID = $('#defaultSeverID').val();
					
				param['mod'] 		= 'ServerList';
				param['do'] 		= 'defaultSeverID';
				param['s_id'] 			=  s_id;
				param['defaultSeverID'] =  defaultSeverID;
				
				$.ajax({
					type:'POST',
					url:'index.php',
					data:param,
					dataType:'html',
					success:function(data) {
				 		var dataObj = eval("(" + data + ")");//转换为json对象
						if (dataObj.code != 1) {
							alert(dataObj.msg);
							window.location.href = window.location.href;
						} else {
							// 保存成功  要重新刷新 
							alert(dataObj.msg);
							// window.location.href = window.location.href;
						} 
					}
				});
			}
		    
		    /**
		              保存
		    */
			function formSubmit(severId) {
				
				if(!severId) {
					alert("serverId异常,请联系管理员!");
					return ;
				}
				
				var param = {};
				var s_id = "<?php echo $this->_tpl_vars['s_id']; ?>
";
				if(!s_id) {
					alert("s_id不存在,请联系管理员!");
					return ;
				}
				
				// 暂时不考虑适配
				var game 	 = $('#selectGame').val();
				var platform = $('#platform').val();
					
				param['mod'] 		= 'ServerList';
				param['do'] 		= 'saveServer';
				param['severId'] 	= severId;
				
				param['s_id'] 	= s_id;
				param['id'] 	= $('#' + severId + '_id').val();
				param['name'] 	= $('#' + severId + '_name').val();
				param['address'] = $('#' + severId + '_address').val();
				param['port'] 	= $('#' + severId + '_port').val();
				param['state'] 	= $('#' + severId + '_state').val();
				param['order'] 	= $('#' + severId + '_order').val();
				
				if(!param['name']) {
					alert("请输入服名称");
					return ;
				}
				if(!param['address']) {
					alert("请输入服务器ip");
					return ;
				}
				if(!param['port']) {
					alert("请输入服务器端口");
					return ;
				}
				if(!param['state']) {
					alert("请输入state");
					return ;
				}
				if(!param['order']) {
					alert("请输入order");
					return ;
				}
				
				$.ajax({
					type:'POST',
					url:'index.php',
					data:param,
					dataType:'html',
					success:function(data) {
				 		var dataObj = eval("(" + data + ")");//转换为json对象
						if (dataObj.code != 1) {
							alert(dataObj.msg);
							window.location.href = window.location.href;
						} else {
							// 保存成功  要重新刷新 
							alert(dataObj.msg);
							// window.location.href = window.location.href;
						} 
					}
				});
				
			}
			
			function configure(type, device) {
				if(device == "pc") {
					var game = $('#selectGame').val();
					var platform = $('#platform').val();
				} else if(device == "move") {
					var game = $('#selectGame2').val();
					var platform = $('#platform2').val();
				}
				
				if (!game) {
					alert('请选择游戏');
				}  else {
						url = "index.php?mod=ServerList&do=configure&action=1&game="
							+ game
							+ "&platform="
							+ platform
							+ "&type="
							+ type;
					window.location.href = url;
				}
			}
			
			// 适配
			window.onload = function(){
				/* var width = document.documentElement.clientWidth;
				if(width < 1700) {
					$('#pcDevice').css("display", "none");
					$('#moveDevice').css("display", "block");
				} else if(width > 1700) {
					$('#pcDevice').css("display", "block");
					$('#moveDevice').css("display", "none");
				} */
			}
			
		</script>
		
	
		
<?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "footer.html", 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>